Fix int overflowing in ExcelGeneralNumberFormat #1497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We're seeing this An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Rounding digits must be between 0 and 15, inclusive. coming from ExcelGeneralNumberFormat line 98.
This is caused by a wrong data type used in the digits counting algorithm. When calculating the len on line 96:
int len = (int)Math.Log10((**int**)Math.Abs(value)) + 1;
Casting a double to an int, you can easily end up with int overflow. When this happens, you end up with len like -2147483647.
Numbers higher than 10,000,000,000 are handled correctly line 77. But there is plenty of numbers between max int 2,147,483,647 and 10,000,000,000 that trigger the overflow.